// @ts-nocheck
/* eslint-disable */
import SXYJSBridge from './index.js'
import envJudge from '@/lib/judge-env.js';
import * as clipboard from 'clipboard-polyfill'
import store from '@/store'

const env = envJudge();
const isApp = ['IOS', 'android'].includes(env); // 是不是App

// 设置标题
function setNativeTitle( data, callback, sync) {
    let func = 'naviConfig';
    SXYJSBridge.callHandler(func, data, callback, sync)
}

// 跳转原生页面
function goBackNativePage(func, data) {
    SXYJSBridge.callHandler(func, data);
}

// 返回  默认返回并刷新
function goBack(refresh = true) {
    SXYJSBridge.callHandler('back', {refresh});
}

function goBackReload() {
    SXYJSBridge.callHandler('backReload');
}

// 打开新页面 || 页面或者小程序方式
function goNewPage(fun = 'newPage', data) {
    SXYJSBridge.callHandler(fun, data);
}

// 打开媒体文件
function openAlbum(func, data, callback) {
    // if (isApp) {
    SXYJSBridge.callHandler(func, data, (data) => callback(data));
    // return;
    // }

}

// 分享
function share(func, data, callback) {
    if (!isApp) {
        let res = clipboard.writeText(data.content)
        if (callback) {
            callback();
        }
        return;
    }
    SXYJSBridge.callHandler(func, data, callback);
}

// 打开视频媒体
function openVideoOfMaterial(data, callback) {
    SXYJSBridge.callHandler('selectVideoFromMaterial', data, callback);
}

// 预览
function previewMedia(fun, data, callback) {
    SXYJSBridge.callHandler('preview', data, callback);
}

// 获取导航高度
function backNaviHeight (){
    return SXYJSBridge.BridgeMessage;
}

// 打开扫码
function openScan(func, data, callback) {
    if (isApp) {
        if(!func) {
            func = 'scan';
        }
        SXYJSBridge.callHandler(func, data, callback);
    }
}

// 公共通信 只执行一次js函数
function commonJsBridge(func, data, callback, sync) {
    SXYJSBridge.callHandler(func, data, callback);
}

// 公共通信 重复执行js函数
function commonRepeatJsBridge(func, data, callback, sync) {
    SXYJSBridge.callRepeatHandler(func, data, callback);
}

// 进入研会议会议室
function goMeeting(func, data, callback, h5Url) {
    if (isApp) {
        if(!func) {
            func = 'meeting';
        }
        SXYJSBridge.callHandler(func, data, callback);
    } else {
        store.dispatch('jsBridge/disposeBridge', {
            method: 'goNewPage',
            url: h5Url
        });
    }
}

// 进入研会议房间
function jumpToMeetingRoom(func, data) {
    SXYJSBridge.callHandler('listenCourse', data);
}

const jsBridge = {
    setNativeTitle,
    goBackNativePage,
    goBack,
    goNewPage,
    openAlbum,
    previewMedia,
    share,
    commonJsBridge,
    commonRepeatJsBridge,
    goMeeting,
    jumpToMeetingRoom
}

export {
    jsBridge,
    setNativeTitle,
    goBackNativePage,
    goBack,
    goNewPage,
    openAlbum,
    openVideoOfMaterial,
    previewMedia,
    backNaviHeight,
    share,
    commonJsBridge,
    commonRepeatJsBridge,
    openScan,
    goMeeting,
    jumpToMeetingRoom
}
